'''
Created on Jun 4, 2012
TC ID: Ecom_5041
Desc: Kiem thu chuc nang them chu thich cho mot don vi bai hoc
@author: Vu Dao
'''
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.contentFunc import clickOnAddcomment, addANewComment,\
    clickOnSubmitCommentButton, verifyCreateANewComment
from Functions.loginPageFunc import login
from Functions.lessonInformationFunc import clickOnLesson, clickOnContentButton


username=readData("username",index=2)
password=readData("password",index=2)
tm_lesson=readData("lessonName",index=3)
comment=readData("comment")
class Ecom_5041(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5041(self):
        print "Buoc 1: Dang nhap website"
        login(self,username,password)
        
        print "Buoc 2: Click vao bai hoc"
        clickOnLesson(self,tm_lesson)
        
        print "Buoc 3: Click vao Content"
        clickOnContentButton(self)
        
        print "Buoc 4: Click vao Add comment"
        clickOnAddcomment(self)
        
        print "Buoc 5: Nhap chu thich cho mot don vi bai hoc"
        addANewComment(self,comment)
        
        print "Buoc 6: Click vao nut Submit"
        clickOnSubmitCommentButton(self)
        
        print "Buoc 7: Kiem tra chu thich da duoc them vao hay chua"
        self.assertTrue(verifyCreateANewComment(self,comment), "Failed: them chu thich vao mot don vi bai hoc chua thanh cong")
        print "Them chu thich ve mot don vi bai hoc thanh cong"
        
    
    def tearDown(self):
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5041)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang them chu thich cho mot don vi bai hoc'
                    )
    runner.run(suite)